#include("../../layout/header.html")
#@layout()
#define content()
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 表格工具栏 -->
      <form class="layui-form toolbar">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">关键字:</label>
            <div class="layui-input-inline">
              <input name="searchValue" class="layui-input" placeholder="输入表名、表备注"/>
            </div>
          </div>

          <div class="layui-inline">&emsp;
            <button class="layui-btn icon-btn" lay-filter="dataTbSearch" lay-submit>
              <i class="layui-icon">&#xe615;</i>搜索
            </button>

          </div>
        </div>
      </form>
      <!-- 数据表格 -->
      <table id="dataTable" lay-filter="dataTable"></table>
    </div>
  </div>
</div>

<!-- js部分 -->
<script>
  layui.use(['layer', 'form', 'table', 'util', 'admin','formX'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var util = layui.util;
    var formX = layui.formX;
    var admin = layui.admin;
    /* 渲染表格 */
    var insTb = table.render({
      elem: '#dataTable',
      url: '/gen/genTable/dbList',
      page: true,
      cellMinWidth: 100,
      toolbar: ['<p>',
        '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon layui-icon-export"></i>导入</button>&nbsp;',
        '</p>'].join(''),
      cols: [[
        {type: 'checkbox'},
        {type: 'numbers'},
        {field: 'tableName', title: '表名', sort: true},
        {field: 'tableComment', title: '表描述', sort: true},
        {
          field: 'createTime', title: '创建时间'
        },
        {
          field: 'updateTime', title: '最后更新时间'
        }
      ]]
    });

    /* 表格头工具栏点击事件 */
    table.on('toolbar(dataTable)', function (obj) {
      if (obj.event === 'add') { // 添加
        var checkRows = table.checkStatus('dataTable');
        if (checkRows.data.length === 0) {
          layer.msg('请选择要添加的数据', {icon: 2});
          return;
        }
        var tableNames = checkRows.data.map(function (d) {
          return d.tableName;
        });
        console.log(tableNames)
        var loadIndex = layer.load(2);
        admin.req('/gen/genTable/import?tableNames=' + tableNames,{},function (d) {
          if (0 === d.code) {
            layer.close(loadIndex);
            layer.msg(d.msg, {icon: 1});
            window.parent.insTb.reload({page: {curr: 1}});
          }else {
            layer.msg(d.msg, {icon: 2});
          }
        })
        return false;
      }
    });

    /* 表格搜索 */
    form.on('submit(dataTbSearch)', function (data) {
      insTb.reload({where: data.field, page: {curr: 1}});
      return false;
    });

  });
</script>
</body>
#end